/*
 * This file is part of the Sx Framework Library.
 * 
 * Copyright (C) 2013 University of Colorado Denver
 * <min.choi@ucdenver.edu> <shane.transue@ucdenver.edu>
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy 
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
 * copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in 
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 */
#include <sxMassSpringMesh.h>

Sx::Simulation::Objects::MassSpringMesh::MassSpringMesh() : SimulationMesh() {}

Sx::Simulation::Objects::MassSpringMesh::~MassSpringMesh() {}

bool Sx::Simulation::Objects::MassSpringMesh::addNodeExternalForce(unsigned int index, Eigen::Vector3d& force) {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return false;
	this->representation.getPhysicalRepresentation()->addNodeExternalForce(index, force);
	return true;
}

bool Sx::Simulation::Objects::MassSpringMesh::addNodeVelocity(unsigned int index, Eigen::Vector3d& velocity) {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return false;
	this->representation.getPhysicalRepresentation()->addNodeVelocity(index, velocity);
	return true;
}

bool Sx::Simulation::Objects::MassSpringMesh::addNodePosition(unsigned int index, Eigen::Vector3d& position) {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return false;
	this->representation.getPhysicalRepresentation()->addNodePosition(index, position);
	return true;
}

bool Sx::Simulation::Objects::MassSpringMesh::addNodeMass(unsigned int index, double mass) {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return false;
	this->representation.getPhysicalRepresentation()->addNodeMass(index, mass);
	return true;
}

bool Sx::Simulation::Objects::MassSpringMesh::setNodeExternalForce(unsigned int index, Eigen::Vector3d& force) {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return false;
	this->representation.getPhysicalRepresentation()->setNodeExternalForce(index, force);
	return true;
}

bool Sx::Simulation::Objects::MassSpringMesh::setNodeExternalForce(unsigned int index, double x, double y, double z) {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return false;
	this->representation.getPhysicalRepresentation()->setNodeExternalForce(index, x, y, z);
	return true;
}

bool Sx::Simulation::Objects::MassSpringMesh::setNodeInternalForce(unsigned int index, Eigen::Vector3d& force) {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return false;
	this->representation.getPhysicalRepresentation()->setNodeInternalForce(index, force);
	return true;
}

bool Sx::Simulation::Objects::MassSpringMesh::setNodeInternalForce(unsigned int index, double x, double y, double z) {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return false;
	this->representation.getPhysicalRepresentation()->setNodeInternalForce(index, x, y, z);
	return true;
}

bool Sx::Simulation::Objects::MassSpringMesh::setNodeVelocity(unsigned int index, Eigen::Vector3d& velocity) {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return false;
	this->representation.getPhysicalRepresentation()->setNodeVelocity(index, velocity);
	return true;
}

bool Sx::Simulation::Objects::MassSpringMesh::setNodeVelocity(unsigned int index, double x, double y, double z) {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return false;
	this->representation.getPhysicalRepresentation()->setNodeVelocity(index, x, y, z);
	return true;
}

bool Sx::Simulation::Objects::MassSpringMesh::setNodePosition(unsigned int index, Eigen::Vector3d& position) {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return false;
	this->representation.getPhysicalRepresentation()->setNodePosition(index, position);
	return true;
}

bool Sx::Simulation::Objects::MassSpringMesh::setNodePosition(unsigned int index, double x, double y, double z) {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return false;
	this->representation.getPhysicalRepresentation()->setNodePosition(index, x, y, z);
	return true;
}

bool Sx::Simulation::Objects::MassSpringMesh::setNodePreviousPosition(unsigned int index, Eigen::Vector3d& position) {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return false;
	this->representation.getPhysicalRepresentation()->setNodePreviousPosition(index, position);
	return true;
}

bool Sx::Simulation::Objects::MassSpringMesh::setNodeMass(unsigned int index, double mass) {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return false;
	this->representation.getPhysicalRepresentation()->setNodeMass(index, mass);
	return true;
}

bool Sx::Simulation::Objects::MassSpringMesh::setNodeAcceleration(unsigned int index, Eigen::Vector3d& acceleration) {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return false;
	this->representation.getPhysicalRepresentation()->setNodeAcceleration(index, acceleration);
	return true;
}

bool Sx::Simulation::Objects::MassSpringMesh::setNodeAcceleration(unsigned int index, double x, double y, double z) {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return false;
	this->representation.getPhysicalRepresentation()->setNodeAcceleration(index, x, y, z);
	return true;
}

bool Sx::Simulation::Objects::MassSpringMesh::setSubsteps(unsigned int substeps) {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return false;
	this->representation.getPhysicalRepresentation()->setSubsteps(substeps);
	return true;
}

bool Sx::Simulation::Objects::MassSpringMesh::setStationary(bool stationary) {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return false;
	this->representation.getPhysicalRepresentation()->setStationary(stationary);
	return true;
}

bool Sx::Simulation::Objects::MassSpringMesh::setStatic(bool stationary) {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return false;
	this->representation.getPhysicalRepresentation()->setStatic(stationary);
	return true;
}

bool Sx::Simulation::Objects::MassSpringMesh::isStatic() const {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return false;
	return this->representation.getPhysicalRepresentation()->isStatic();
}

bool Sx::Simulation::Objects::MassSpringMesh::isStationary() const {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return false;
	return this->representation.getPhysicalRepresentation()->isStationary();
}

bool Sx::Simulation::Objects::MassSpringMesh::reset() {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return false;
	return this->representation.getPhysicalRepresentation()->reset();
}

unsigned int Sx::Simulation::Objects::MassSpringMesh::getNumNodes() const {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return false;
	return this->representation.getPhysicalRepresentation()->getVertices().size();
}

unsigned int Sx::Simulation::Objects::MassSpringMesh::getNodeCount() const {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return false;
	return this->representation.getPhysicalRepresentation()->getVertices().size();
}

bool Sx::Simulation::Objects::MassSpringMesh::zeroExternalForces() const {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return false;
	this->representation.getPhysicalRepresentation()->zeroExternalForces();
	return true;
}

Eigen::Vector3d Sx::Simulation::Objects::MassSpringMesh::getNodeExternalForce(unsigned int index) const {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return Eigen::Vector3d::Zero();
	return this->representation.getPhysicalRepresentation()->getNodeExternalForce(index);
}

Eigen::Vector3d Sx::Simulation::Objects::MassSpringMesh::getNodeAcceleraction(unsigned int index) const {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return Eigen::Vector3d::Zero();
	return this->representation.getPhysicalRepresentation()->getNodeAcceleraction(index);
}

Eigen::Vector3d Sx::Simulation::Objects::MassSpringMesh::getNodeVelocity(unsigned int index) const {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return Eigen::Vector3d::Zero();
	return this->representation.getPhysicalRepresentation()->getNodeVelocity(index);
}

Eigen::Vector3d Sx::Simulation::Objects::MassSpringMesh::getNodePosition(unsigned int index) const {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return Eigen::Vector3d::Zero();
	return this->representation.getPhysicalRepresentation()->getNodePosition(index);
}

Eigen::Vector3d Sx::Simulation::Objects::MassSpringMesh::getNodePrevPosition(unsigned int index) const {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return Eigen::Vector3d::Zero();
	return this->representation.getPhysicalRepresentation()->getNodePrevPosition(index);
}

Eigen::Vector3d Sx::Simulation::Objects::MassSpringMesh::getNodePrevVelocity(unsigned int index) const {
	if ( this->representation.getPhysicalRepresentation() == nullptr ) return Eigen::Vector3d::Zero();
	return this->representation.getPhysicalRepresentation()->getNodePrevVelocity(index);
}
